/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package MembuatLaporan;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.util.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
import javax.swing.JLabel;
import javax.swing.Timer;

/**
 *
 * @author asus
 */
public class LaporanController {
    private Connection connect;
    private static LaporanController lapor;
    
    public LaporanController(Connection konek) {
        this.connect = konek;
    }

    public LaporanController() {
    }

    public static LaporanController getKoneksiKontrol() throws SQLException, FileNotFoundException, IOException {
        if (lapor == null) {
            lapor = new LaporanController(Koneksi.koneksi.getDBConnection());
        }
        return lapor;

    }
    public static void showDateAndClock(final JLabel tanggalbeli, final JLabel jamLabel1) {
        /**
         *
         * @author Anonim, via search google.com
         */
//         */
        ActionListener taskPerformer = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                GregorianCalendar gc = new GregorianCalendar();
                SimpleDateFormat frmtDate = new SimpleDateFormat("dd-MMM-yyyy");

                String nol_jam = "", nol_menit = "", nol_detik = "";

                java.util.Date dateTime = new java.util.Date();
                int nilai_jam = dateTime.getHours();
                int nilai_menit = dateTime.getMinutes();
                int nilai_detik = dateTime.getSeconds();

                if (nilai_jam <= 9) {
                    nol_jam = "0";
                }
                if (nilai_menit <= 9) {
                    nol_menit = "0";
                }
                if (nilai_detik <= 9) {
                    nol_detik = "0";
                }

                String jam = nol_jam + Integer.toString(nilai_jam);
                String menit = nol_menit + Integer.toString(nilai_menit);
                String detik = nol_detik + Integer.toString(nilai_detik);

                jamLabel1.setText(jam + " : " + menit + " : " + detik + " WIB");
                tanggalbeli.setText(frmtDate.format(gc.getTime()));
            }
        };
        new Timer(1000, taskPerformer).start();
    }
    public static List<Laporan> getAllDataJual(String tglAwal, String tglAkhir) throws SQLException, FileNotFoundException, IOException {
        return Laporan.getKoneksiKontrol().getAllDataJual(tglAwal, tglAkhir);
    }
    
    public static void ubahStatusPemb(String notrans) throws FileNotFoundException, IOException, SQLException{
        Laporan.getKoneksiKontrol().ubahStatusPemb(notrans);
    }
    
    public static void ubahStatusPenj(String notrans) throws FileNotFoundException, IOException, SQLException{
        Laporan.getKoneksiKontrol().ubahStatusPenj(notrans);
    }
}
